﻿using Styx;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Styx.TreeSharp;
using Action = Styx.TreeSharp.Action;

using CommonBehaviors.Actions;


namespace Crusader
{
    partial class Routine : CombatRoutine
    {

        partial class Paladin
        {

            #region Statics

            double CSCD = 0.5;


            #endregion


            #region Combat composites

            public static Composite RetributionCombatBehavior()
            {
                return new Decorator(ret => Me.CurrentTarget != null && !Me.Mounted,
                    new PrioritySelector(
                        AutoAttack(),

                        // WoW 5.0.x - Rotations.
                        // Single target == Inq > 5HP TV > HoW > Exo > CS > Judge > 3-4HP TV (> SS)
                        // Multitarget ==   Inq > 5HP DS > HoW > Exo > HotR > Judge > 3-4HP DS
                        
                        CastSpell("Flash of Light", Me, ret => PlayerHasBuffStacks("Selfless Healer") >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Ret_FL),
                        CastSpell("Word of Glory", Me, ret => CurrentHolyPower() >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Ret_WoG),
                        CastSpell("Eternal Flame", Me, ret => CurrentHolyPower() >= 3 && Me.HealthPercent < Crusader.Settings.Instance.Paladin_Ret_WoG),

                        CastSpell("Seal of Righteousness", ret => (Crusader.Settings.Instance.Paladin_Seal == Seal.SoR || Crusader.Settings.Instance.Paladin_Seal == Seal.Auto && (EnemyUnits.Count > Crusader.Settings.Instance.Paladin_Ret_SealSwitch) && !Me.HasAura("Seal of Righteousness"))),
                        CastSpell("Seal of Truth", ret => (Crusader.Settings.Instance.Paladin_Seal == Seal.SoT || Crusader.Settings.Instance.Paladin_Seal == Seal.Auto && (EnemyUnits.Count < Crusader.Settings.Instance.Paladin_Ret_SealSwitch) && !Me.HasAura("Seal of Truth"))),


                        //Melee Rotation
                        new Decorator(ret => Settings.Instance.Paladin_Ret_Rotation == 0,
                            new PrioritySelector(

                                AoETargeting(),
                                
                                new Decorator(ret => ((CurrentHolyPower() >= 3) || PlayerHasBuff("Divine Purpose")),
                                    new PrioritySelector(
                                        CastSpell("Inquisition", ret => (PlayerBuffTimeLeft("Inquisition") <= 5))
                                )),

                                new Decorator(ret => ValidUnit(Me.CurrentTarget) &&( Settings.Instance.Paladin_Ret_ExS == Settings.CD.OnCooldown || Settings.Instance.Paladin_Ret_ExS == Settings.CD.DuringCoolDown && (PlayerHasBuff("Avenging Wrath") || SpellCooldown("Avenging Wrath") > 87)),
                                    CastSpell("Execution Sentence")),

                                //Ranged Rotation
                                new Decorator(ret => Settings.Instance.Paladin_Ret_UseRanged_Rotation && !Me.CurrentTarget.IsWithinMeleeRange,
                                    new PrioritySelector(
                                            CastSpell("Hammer of Wrath", ret => (Me.CurrentTarget.HealthPercent < 20 || PlayerHasBuff("Avenging Wrath"))),
                                            CastHammerOfWrath(),
                                            CastSpell("Exorcism", ret=> !PlayerHasGlyph("Mass Exorcism")),
                                            CastSpell("Judgment"),
                                            CastSpell("Word of Glory", ret => CurrentHolyPower() >= 3 && PlayerHasGlyph("Harsh Words"))
                                        )),

                                // Holy Avenger
                                new Decorator(ret => PlayerBuffTimeLeft("Holy Avenger") > 0,
                                    new PrioritySelector(
                                        CastSpell("Divine Storm", ret => CurrentHolyPower() >= 3 && (Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.Paladin_Ret_DSOverTV)),
                                        CastSpell("Templar's Verdict", ret => CurrentHolyPower() >= 3),
                                        CastSpell("Hammer of the Righteous", ret => (Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.Paladin_Ret_HotROverCS)),
                                        CastSpell("Exorcism"),
                                        new Decorator(ret => Crusader.Settings.Instance.Paladin_Ret_JudgmentBonus,
                                        DoubleJeopardy()),
                                        CastSpell("Crusader Strike"),
                                        CastJudgment()
                                        )),

                                //Make sure Inq is up before using TV/DS.
                                new Decorator(ret => (CurrentHolyPower() >= 5 && PlayerBuffTimeLeft("Inquisition") > 5),
                                    new PrioritySelector(
                                    CastSpell("Divine Storm", ret => (Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.Paladin_Ret_DSOverTV)),
                                    CastSpell("Templar's Verdict"))),
                                    CastOnGround("Light's Hammer", ret => StyxWoW.Me.CurrentTarget.Location, ret => Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= 2),
                                    CastSpell("Hammer of Wrath", ret => (Me.CurrentTarget.HealthPercent < 20 || PlayerHasBuff("Avenging Wrath"))),
                                    CastHammerOfWrath(),
                                    CastSpell("Exorcism"),

                                    CastSpell("Hammer of the Righteous", ret => (Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.Paladin_Ret_HotROverCS)),

                                    //Check for Double Jeopardy
                                    new Decorator(ret => Crusader.Settings.Instance.Paladin_Ret_JudgmentBonus,
                                    DoubleJeopardy()),

                                    CastSpell("Crusader Strike"),
                                    CastJudgment(),
                                    //Make sure Inq is up before using TV/DS, just incase.
                                    new Decorator(ret => (CurrentHolyPower() >= 3 && PlayerBuffTimeLeft("Inquisition") > 4),
                                        new PrioritySelector(
                                            CastSpell("Divine Storm", ret => (Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.Paladin_Ret_DSOverTV)),
                                            CastSpell("Templar's Verdict")))
                                
                        )),
                        
                        // Sacred Shield

                        CastSpell("Sacred Shield", Me ,ret => Crusader.Settings.Instance.Paladin_Ret_UseSS && PlayerBuffTimeLeft(20925) < 2 ),
                        

                        UseTrinket1("Avenging Wrath"),
                        UseTrinket2("Avenging Wrath"),
                        UseGloves("Avenging Wrath")

                    )
                );
            }

            #endregion
        }
    }
}



/*
 Old cooldown stuff.
    //Not Tier12 CD Rotation.
                       new Decorator(ret => Settings.Instance.Paladin_Ret_Tier != Settings.Tier.T12,
                            new PrioritySelector(
                                CastCooldown("Guardian of Ancient Kings", ret => Settings.Instance.UseCooldowns && PlayerBuffTimeLeft("Inquisition") > 20 &&
                                                                                         (SpellCooldown("Zealotry") > 60 || SpellCooldown("Zealotry") < 10)),
                                CastCooldown("Zealotry", ret => (Me.CurrentHolyPower == 3 || PlayerHasBuff("Divine Purpose")) &&
                                                                                         PlayerBuffTimeLeft("Guardian of Ancient Kings") <= 20 &&
                                                                                         SpellCooldown("Guardian of Ancient Kings") >= 15),
                                CastCooldown("Avenging Wrath", ret => PlayerHasBuff("Zealotry"))
                            )
                        ),

                        //Tier12 CD Rotation
                        new Decorator(ret => Settings.Instance.Paladin_Ret_Tier == Settings.Tier.T12,
                            new PrioritySelector(
                                CastCooldown("Zealotry", ret => Settings.Instance.UseCooldowns && (Me.CurrentHolyPower == 3 || PlayerHasBuff("Divine Purpose"))),
                                CastCooldown("Guardian of Ancient Kings", ret => PlayerHasBuff("Zealotry") && PlayerBuffTimeLeft("Zealotry") <=31),
                                CastCooldown("Avenging Wrath", ret => PlayerHasBuff("Zealotry") && PlayerBuffTimeLeft("Zealotry") <=21)
                            )
                        ),
 
 * 


                        //Inq > CS > TV > HoW > Exo > J > HW > Cons
                        new Decorator(ret => Settings.Instance.Paladin_Ret_Rotation == 0,
                            new PrioritySelector(

                                CastSpell("Divine Storm", ret => Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= Crusader.Settings.Instance.AoEAt),
                                CastSpell("Crusader Strike", ret => Me.CurrentHolyPower < 3),

                                new Decorator(ret => Me.CurrentHolyPower == 3 || PlayerHasBuff("Divine Purpose"),
                                    new PrioritySelector(
                                        CastSpell("Inquisition", ret => PlayerBuffTimeLeft("Inquisition") < 5),
                                        CastSpell("Templar's Verdict")
                                )),

                                new Decorator(ret => SpellCooldown("Crusader Strike") > 0.5 || Me.CurrentHolyPower == 3,
                                    new PrioritySelector(

                                        CastSpell("Hammer of Wrath", ret => Me.CurrentTarget.HealthPercent < 20 ||
                                                                               PlayerHasBuff("Avenging Wrath")),
                                        CastSpell("Exorcism", ret => PlayerHasBuff("The Art of War")),
                                        CastSpell("Judgement"),
                                        CastSpell("Holy Wrath", ret => ShouldWeAoe() && Me.ManaPercent > Crusader.Settings.Instance.Paladin_Ret_HolyWrathMana),
                                        CastSpell("Consecration", ret => ShouldWeAoe() && Me.ManaPercent > Crusader.Settings.Instance.Paladin_Ret_ConsMana)
                                    )
                                )
                        )),

                        //Inq > CS > HoW > Exo > TV > J > HW > Cons
                        new Decorator(ret => Settings.Instance.Paladin_Ret_Rotation == 1,
                            new PrioritySelector(

                                CastSpell("Divine Storm", ret => Crusader.Settings.Instance.AllowAoE && EnemyUnits.Count >= 4 && !IsTargetBoss()),
                                CastSpell("Crusader Strike", ret => Me.CurrentHolyPower < 3),

                                CastSpell("Inquisition", ret => PlayerBuffTimeLeft("Inquisition") < 5 && (Me.CurrentHolyPower == 3 || PlayerHasBuff("Divine Purpose"))),

                                new Decorator(ret => SpellCooldown("Crusader Strike") > 0.5 || Me.CurrentHolyPower == 3,
                                    new PrioritySelector(

                                        CastSpell("Hammer of Wrath", ret => Me.CurrentTarget.HealthPercent < 20 ||
                                                                               PlayerHasBuff("Avenging Wrath")),
                                        CastSpell("Exorcism", ret => PlayerHasBuff("The Art of War")),
                                        CastSpell("Templar's Verdict", ret => Me.CurrentHolyPower == 3 || PlayerHasBuff("Divine Purpose")),
                                        CastSpell("Judgement"),
                                        CastSpell("Holy Wrath", ret => ShouldWeAoe() && Me.ManaPercent > Crusader.Settings.Instance.Paladin_Ret_HolyWrathMana),
                                        CastSpell("Consecration", ret => ShouldWeAoe() && Me.ManaPercent > Crusader.Settings.Instance.Paladin_Ret_ConsMana)
                                    )
                                )
                        )),
 * 
 */